package com.chenailin.www.controller;

import com.chenailin.www.pojo.Administrator;
import com.chenailin.www.service.AdministratorService;

import java.util.Objects;
import java.util.Scanner;

import static com.chenailin.www.util.InputValidator.confirmPassword;

public class AdministratorController {

    private final Scanner sc = new Scanner(System.in);
    AdministratorService administratorService = new AdministratorService();

    // 修改密码
    public void modifyPassword(Administrator administrator) {
        System.out.println("\n=== 修改密码 ===");
        System.out.println("请输入旧密码:");
        String oldPassword = sc.nextLine();
        if (!Objects.equals(oldPassword, administrator.getPassword())) {
            System.out.println("密码错误！");
            return;
        }
        try {
            administrator.setPassword(confirmPassword());
            if(administratorService.modifyPassword(administrator)) {
                System.out.println("\n密码修改成功！");
            } else {
                System.out.println("修改失败，请检查输入数据");
            }
        } catch (Exception e) {
            System.out.println("修改失败：" + e.getMessage());
        }
    }
}
